package org.example.testError;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author liyishan
 * @date 2025/8/15
 * @description
 */

public class testMember {
    public static void main(String[] args) {
        test_thread_pool_java_heap_space();
    }
    public static void test_thread_pool_java_heap_space() {
        // 创建一个固定大小的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        try {
            // 不断提交占用大量内存的任务
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                executorService.submit(new MemoryHogTask());
            }
        } catch (OutOfMemoryError e) {
            System.out.println("Caught OutOfMemoryError: " + e.getMessage());
        } finally {
            // 关闭线程池
            executorService.shutdown();
        }
    }
}
